#!/usr/bin/env python
# encoding: utf-8
'''
@author: Excelsiorly
@license: (C) Copyright 2021, All Rights Reserved.
@contact: excelsiorly@qq.com
@file: 0013.py
@time: 2021/9/14 12:16
@desc:
'''
class Solution:
    def findLongestWord(self, s: str, dictionary: list) -> str:
        res = ''
        for word in dictionary:
            i = j = 0
            while i < len(s) and j < len(word):
                if s[i]==word[j]:
                    j += 1
                i += 1

            if j==len(word):
                if len(word)>len(res):
                    res = word
                elif len(word)==len(res):
                    res = word if word<res else res

        return res


if __name__ == '__main__':
    sl = Solution()
    s = "abpcplea"
    dic = ["ale","apple","monkey","plea", "abpcplaaa","abpcllllll","abccclllpppeeaaaa"]
    r = sl.findLongestWord(s, dic)
    print(r)